import router from '../router';
import enumList from './enumList';
import enumMap from './enumMap';
import locale from 'ant-design-vue/es/date-picker/locale/zh_CN';
export default {
  install(Vue) {
    Vue.prototype.$enumList = enumList;
    Vue.prototype.$enumMap = enumMap;
    Vue.prototype.$locale = locale;
    Vue.prototype.questionTypeList = {
      // 收集表
      QUESTIONNAIRE: [
        {
          label: '单选',
          value: 'SINGLE_CHOICE'
        },
        {
          label: '多选',
          value: 'MULTIPLE_CHOICE'
        },
        {
          label: '下拉框',
          value: 'DROP_DOWN_BOX'
        },
        {
          label: '文件上传',
          value: 'UPLOAD_FILE'
        },
        {
          label: '填空题',
          value: 'COMPLETION'
        },
        {
          label: '签名题',
          value: 'AUTOGRAPH'
        },
        {
          label: '日期',
          value: 'DATETIME'
        },
        {
          label: '评分单选',
          value: 'SINGLE_CHOICE_SCORE'
        },
        {
          label: '位置',
          value: 'LOCATION'
        }
      ],
      // 投票
      VOTE: [
        {
          label: '单选',
          value: 'SINGLE_CHOICE'
        },
        {
          label: '多选',
          value: 'MULTIPLE_CHOICE'
        },
        {
          label: '下拉框',
          value: 'DROP_DOWN_BOX'
        },
        {
          label: '文件上传',
          value: 'UPLOAD_FILE'
        },
        {
          label: '填空题',
          value: 'COMPLETION'
        },
        {
          label: '签名题',
          value: 'AUTOGRAPH'
        },
        {
          label: '日期',
          value: 'DATETIME'
        },
        {
          label: '评分单选',
          value: 'SINGLE_CHOICE_SCORE'
        },
        {
          label: '位置',
          value: 'LOCATION'
        }
      ],
      ASSESSMENT: [
        {
          label: '单选',
          value: 'SINGLE_CHOICE'
        },
        {
          label: '多选',
          value: 'MULTIPLE_CHOICE'
        },
        {
          label: '下拉框',
          value: 'DROP_DOWN_BOX'
        },
        {
          label: '文件上传',
          value: 'UPLOAD_FILE'
        },
        {
          label: '填空题',
          value: 'COMPLETION'
        },
        {
          label: '签名题',
          value: 'AUTOGRAPH'
        },
        {
          label: '日期',
          value: 'DATETIME'
        },
        {
          label: '评分单选',
          value: 'SINGLE_CHOICE_SCORE'
        },
        {
          label: '位置',
          value: 'LOCATION'
        }
      ]
    };
    Vue.prototype.routePush = function routePush(path) {
      router.push(path)
    }
    Vue.prototype.routeReplace = function routeReplace(path) {
      router.replace(path)
    }
    // 验证登录账号
    Vue.prototype.checkAccount = function checkAccount(rule, value, callback, tip = '请输入登录账号') {
      if (!value) {
        return callback(new Error(typeof tip === 'string' ? tip : '请输入登录账号'));
      }
      const reg = /^(?!\d+$)([\da-zA-Z\u4E00-\u9FA5_]+){6,20}$/;
      if (!reg.test(value)) {
        callback(new Error('6-20个字符，支持字母或字母、数字、汉字的组合'));
      } else {
        callback();
      }
    }
    // 手机号正则校验
    Vue.prototype.checkMobile = function checkMobile(rule, value, callback) {
      if (!value) {
        return callback(new Error('请输入手机号'));
      }
      const reg = /^1[3456789]\d{9}$/;
      if (!reg.test(value)) {
        callback(new Error('请输入正确的手机号'));
      } else {
        callback();
      }
    }
    // 邮箱校验
    Vue.prototype.checkEmail = function checkEmail(rule, value, callback) {
      if (!value) {
        return callback(new Error('请输入邮箱地址'));
      }
      const reg = /^([a-zA-Z]|[0-9])(\w|-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/g;
      if (!reg.test(value)) {
        callback(new Error('请输入正确的邮箱地址'));
      } else {
        callback();
      }
    }
    // 验证身份证号
    Vue.prototype.checkIdNo = function checkIdNo(rule, value, callback) {
      if (!value) {
        return callback(new Error('请输入身份证号'));
      }
      const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/g;
      if (!reg.test(value)) {
        callback(new Error('请输入正确的身份证号'));
      } else {
        callback();
      }
    }
    // 密码校验
    Vue.prototype.checkPwd = function checkPwd(rule, value, callback) {
      if (!value) {
        return callback(new Error('请输入密码'));
      }
      const reg = /^(?=.*[0-9`~!@#_$%^&].*)(?=.*[a-zA-Z].*).{6,20}$/;
      if (!reg.test(value)) {
        callback(new Error('6-20个字符，含数字/大小写字母/符号2种组合'));
      } else {
        callback();
      }
    }
    // 一键复制
    Vue.prototype.copyData = function copyData(id) {
      const e = document.getElementById(id);
      e.select();
      const copy = document.execCommand('Copy');
      window.getSelection().removeAllRanges()
      if (copy) {
        Vue.prototype.$message.success('复制成功');
      } else {
        Vue.prototype.$message.error('复制失败');
      }
    }
    if (typeof FormData !== 'undefined') {
      FormData.prototype.setData = function (name, value) {
        if (typeof this.set === 'function') {
          return this.set(name, value);
        } else {
          return this.append(name, value);
        }
      };
    }
  }
}